package modelo;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.LinkedList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Orden extends ConexionBD implements ProductoOrden{

    private String  cedula;
    private float total;

    public Orden(){
            super();
    }

    public boolean registrar(){
        abrirConexion();
        boolean sw = false;
        Vector<String> v1= new Vector<String>();
    	Vector v2= new Vector();
    	v1.add("codigo");
    	v1.add("cedula");
    	v1.add("total");
    	v1.add("estatus");
    	v2.add(getCodigo());
    	v2.add(getCedula());
    	v2.add(getTotal());
    	v2.add(getEstatus());
        String tira=facade.generar(v1, v2, "Orden");
        //String tira="INSERT INTO Orden (codigo, cedula, total,estatus) VALUES("+getCodigo()+",'"+getCedula()+"',"+getTotal()+",'A')";
        try {
            Statement stam = conexion.createStatement();
            stam.execute(tira);
            sw= true;
        } catch (SQLException ex) {
                 Logger.getLogger(Producto.class.getName()).log(Level.SEVERE, null, ex);
       
             sw= false;
        }
        cerrarConexion();
        return sw;
    }


    
   
    public float getTotal() {
        return total;
    }

    public void setTotal(float total) {
        this.total = total;
    }

    public String getCedula() {
        return cedula;
    }

    public void setCedula(String cedula) {
        this.cedula = cedula;
    }
    
    public void registarProductos(LinkedList<Integer> codigos, LinkedList<Integer> cantidades) {
        abrirConexion();
        for (int i = 0; i < codigos.size(); i++) {
            String tira="INSERT INTO ProductoPorOrden (codigoOrden, codigoProducto,cantidad) VALUES("+getCodigo()+","+codigos.get(i)+","+cantidades.get(i)+")";
            try {
                Statement stam = conexion.createStatement();
                stam.execute(tira);

            } catch (SQLException ex) {
                Logger.getLogger(Orden.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        cerrarConexion();
    }


}
